package pay

import (
	"com.cyt.yunpay/app/service/pay/allinpay"
	"encoding/json"
)

const (
	AllinPay = "allinpay"
)

/**
 * 统一支付方法
 */
func CommonPay(service string, method string, data map[string]interface{}) (map[string]interface{}, map[string]interface{}) {

	result := make(map[string]interface{})
	switch service {
	case AllinPay:
		res, _ := allinpay.Call(method, data)
		// 如果 res[1] 有值则返回错误类型
		if res[1].Interface() != nil {
			errData := res[1].Interface().(error).Error()
			json.Unmarshal([]byte(errData), &result)
			if result["message"] == nil {
				result["message"] = "请求失败";
				result["errCode"] = 50000
			}
			return nil, result
		}

		result := res[0].Interface().(map[string]interface{})
		return result, nil
	}
	
	return result, nil
}
